package com.holly.common_view.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.holly.common.utils.L;

import java.util.ArrayList;
import java.util.List;

/**
 * 2016/11/14 <br/>
 *
 * @author Joey Huang QQ:273179370）
 */

public abstract class BaseViewPagerFragmentAdapter<T extends Fragment> extends FragmentPagerAdapter {
    private final String TAG = L.createTag(this);
    private List<T> mList;

    public BaseViewPagerFragmentAdapter(FragmentManager fm) {
        super(fm);
        mList = new ArrayList<>();
    }

    public void setList(List<T> list) {
        mList.clear();
        if (list != null && list.size() > 0) {
            mList.addAll(list);
            L.d(TAG, "setList: size = " + list.size());
        } else {
            L.d(TAG, "setList: size = 0");
        }
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public final Fragment getItem(int position) {
        return mList.get(position);
    }
}
